﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Versioning;
using System.Windows.Forms;

namespace zykControl
{
    public delegate bool FrmBillSellSelectedConfirm(DataRow theRow);

    [SupportedOSPlatform("windows")]
    public partial class FrmBillSel
    {
        public FrmBillSel(CBillSelBase theBillSel)
        {
            InitializeComponent();
            mBillSel = theBillSel;
        }

        private bool mIsOK;
        private CBillSelBase mBillSel;
        private bool mGridWareLoaded;
        private FrmBillSellSelectedConfirm? mSelectedConfirm;

        /// <summary>
        /// 单据选择通用窗体,返回单据列表选中行的DataRow,如果不成功或者取消则返回Nothing
        /// </summary>
        /// <param name="theBillSel"></param>
        /// <param name="theSelectedConfirm"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static DataRow? ShowA(CBillSelBase theBillSel, FrmBillSellSelectedConfirm? theSelectedConfirm = null)
        {
            var me = new FrmBillSel(theBillSel)
            {
                mIsOK = false,
                mGridWareLoaded = false,
                mBillSel = theBillSel,
                mSelectedConfirm = theSelectedConfirm,
                Text = theBillSel.Title
            };
            me.CreateArgs();
            me.dgvList.Columns.Clear();
            me.dgvWare.Columns.Clear();
            me.RefreshMe(true);
            if (theBillSel.Controls.Count > 4) me.Height += (theBillSel.Controls.Count - 4) * 40;
            me.ShowDialog();
            if (theBillSel.BillWidthsDefault != null) me.dgvList.SaveLayout();
            if (me.mGridWareLoaded && theBillSel.DetailWidthsDefault != null) me.dgvWare.SaveLayout();
            if (me.dgvList.Columns.Count == 0) return null;
            if (me.mIsOK)
            {
                return ((DataRowView?)me.dgvList.SelectedRow?.DataBoundItem)?.Row;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 创建参数控件
        /// </summary>
        /// <remarks></remarks>
        private void CreateArgs()
        {
            tblArgs.Controls.Clear();
            tblArgs.RowCount = 1;
            tblArgs.RowStyles.Clear();
            tblArgs.RowStyles.Add(new RowStyle(SizeType.Absolute, 8f));
            for (int xx = 0, loopTo = mBillSel.Controls.Count - 1; xx <= loopTo; xx++)
            {
                tblArgs.RowCount += 1;
                switch (mBillSel.Controls[xx].Args)
                {
                    case EmBillSelBaseArgs.DateSelectArea:
                        {
                            var dDateSelect = new DateSelect();
                            CBillSelDateSelectArea dControl = (CBillSelDateSelectArea)mBillSel.Controls[xx];
                            dDateSelect.SetDate(dControl.StartDate, dControl.EndDate);
                            dDateSelect.Tag = dControl;
                            dDateSelect.Margin = new Padding(3, 0, 0, 0);
                            tblArgs.Controls.Add(dDateSelect, 0, xx + 1);
                            tblArgs.SetColumnSpan(dDateSelect, 2);
                            tblArgs.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));
                            dDateSelect.KeyDown += DateSelectKeyDown;
                            dDateSelect.KeyPress += TextBoxKeyPress;
                            dDateSelect.ValueChanged += DateSelectValueChanged;
                            break;
                        }

                    case EmBillSelBaseArgs.TextBox:
                        {
                            var dTextBox = new TextBox();
                            var dLabel = new Label();
                            CBillSelTextBox dControl = (CBillSelTextBox)mBillSel.Controls[xx];
                            dLabel.AutoSize = true;
                            dLabel.Margin = new Padding(3, 3, 2, 5);
                            dLabel.Text = dControl.Caption;
                            dTextBox.Text = dControl.Text;
                            dTextBox.Tag = dControl;
                            dTextBox.Margin = new Padding(0);
                            dTextBox.KeyDown += TextBoxKeyDown;
                            dTextBox.KeyDown += ControlKeyDown;
                            dTextBox.KeyPress += TextBoxKeyPress;
                            dTextBox.Enter += TextBoxEnter;
                            dTextBox.Leave += TextBoxLeave;
                            tblArgs.Controls.Add(dLabel, 0, xx + 1);
                            tblArgs.Controls.Add(dTextBox, 1, xx + 1);
                            tblArgs.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));
                            break;
                        }

                    case EmBillSelBaseArgs.TextItem:
                        {
                            var dTextItem = new TxtItem();
                            var dLabel = new Label();
                            CBillSelTextItem dControl = (CBillSelTextItem)mBillSel.Controls[xx];
                            dLabel.AutoSize = true;
                            dLabel.Margin = new Padding(3, 3, 2, 5);
                            dLabel.Text = dControl.Caption;
                            dTextItem.SetValue(dControl.Value, dControl.DisplayText);
                            dTextItem.Tag = dControl;
                            dTextItem.AllowClear = true;
                            dTextItem.Dock = DockStyle.Top;
                            dTextItem.Margin = new Padding(0);
                            dTextItem.FindData += TextItemFindData;
                            dTextItem.KeyDown += ControlKeyDown;
                            dTextItem.ValueChanged += TextItemValueChanged;
                            tblArgs.Controls.Add(dLabel, 0, xx + 1);
                            tblArgs.Controls.Add(dTextItem, 1, xx + 1);
                            tblArgs.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));
                            break;
                        }

                    case EmBillSelBaseArgs.Descrioption:
                        {
                            var dLabel1 = new Label()
                            {
                                AutoSize = true,
                                Margin = new Padding(3, 3, 2, 5),
                                ForeColor = Color.Green,
                                Dock = DockStyle.Right
                            };
                            CBillSelDescription dControl = (CBillSelDescription)mBillSel.Controls[xx];
                            dLabel1.Tag = dControl;
                            dLabel1.Text = dControl.Description;
                            dControl.SetLabel(dLabel1);
                            tblArgs.Controls.Add(dLabel1, 0, xx + 1);
                            tblArgs.SetColumnSpan(dLabel1, 2);
                            tblArgs.RowStyles.Add(new RowStyle(SizeType.Absolute, 40f));
                            break;
                        }
                }
            }
        }

        private void ControlKeyDown(object? sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Up:
                    {
                        e.Handled = true;
                        dgvList.MoveUpSelect();
                        break;
                    }

                case Keys.Down:
                    {
                        e.Handled = true;
                        dgvList.MoveDownSelect();
                        break;
                    }
            }
        }

        private void DateSelectValueChanged(object? sender, EventArgs? e)
        {
            if (Created == false || sender == null) return;
            DateSelect dItem = (DateSelect)sender;
            CBillSelDateSelectArea dControl = (CBillSelDateSelectArea)dItem.Tag!;
            dControl.SetDate(dItem.StartDate, dItem.EndDate);
            RefreshMe();
        }

        private void DateSelectKeyDown(object? sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && sender != null)
            {
                if (((DateSelect)sender).dtEnd.Focused == false)
                {
                    ((DateSelect)sender).dtEnd.Focus();
                }
                else
                {
                    SendKeys.Send("\t");
                }
            }
        }

        /// <summary>
        /// 加载各列的宽度设置,仅应由RefreshMe使用
        /// </summary>
        /// <remarks></remarks>
        private void SetBillWidthsDefault()
        {
            if (mBillSel.BillWidthsDefault is null)
            {
                dgvList.AutoResizeColumns();
                return;
            }

            for (int xx = 0; xx < mBillSel.BillWidthsDefault.Length; xx++)
            {
                if (xx >= dgvList.Columns.Count) return;
                if (mBillSel.BillWidthsDefault[xx] > 0)
                    dgvList.Columns[xx].Width = mBillSel.BillWidthsDefault[xx];
            }
        }

        private void SetDetailWidthsDefault()
        {
            if (mBillSel.DetailWidthsDefault is null)
            {
                dgvWare.AutoResizeColumns();
                return;
            }

            for (int xx = 0; xx < mBillSel.DetailWidthsDefault.Length; xx++)
            {
                if (xx >= dgvWare.Columns.Count) return;
                dgvWare.Columns[xx].Width = mBillSel.DetailWidthsDefault[xx];
            }
        }

        private void TextBoxKeyDown(object? sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter || sender == null) return;

            TextBox dItem = (TextBox)sender;
            CBillSelTextBox dControl = (CBillSelTextBox)dItem.Tag!;
            bool dIsTextChanged = (dControl.Text ?? "") != (dItem.Text.Trim() ?? "");
            dControl.SetText(dItem.Text.Trim());
            if (dIsTextChanged == false)
            {
                SendKeys.Send("\t");
                return;
            }

            RefreshMe();
        }

        private void TextBoxKeyPress(object? sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r') e.Handled = true;
        }

        private void TextBoxEnter(object? sender, EventArgs? e)
        {
            ((TextBox?)sender)?.SelectAll();
        }

        private void TextBoxLeave(object? sender, EventArgs? e)
        {
            if (Created == false || sender == null) return;

            TextBox dItem = (TextBox)sender;
            CBillSelTextBox dControl = (CBillSelTextBox)dItem.Tag!;
            dItem.Text = dControl.Text;
        }

        private void TextItemFindData(object sender, TxtItemFindDateArgs e)
        {
            TxtItem dItem = (TxtItem)sender;
            if (e.IsKeyPress && string.IsNullOrEmpty(dItem.Text))
            {
                SendKeys.Send("\t");
                return;
            }

            CBillSelTextItem dControl = (CBillSelTextItem)dItem.Tag!;
            var dValue = dControl.SelectValue(dItem.Text);
            if (dValue is null || dValue.Value is null) return;

            dItem.SetValue(dValue.Value, dValue.DisplayText);
        }

        private void TextItemValueChanged(object? sender, EventArgs e)
        {
            if (sender == null) return;
            TxtItem dItem = (TxtItem)sender;
            CBillSelTextItem dControl = (CBillSelTextItem)dItem.Tag!;
            dControl.SetValue(dItem.Value, dItem.DisplayText);
            if (Created) RefreshMe();
        }

        /// <summary>
        /// 从DataTable当中的一个列,创建一个DataGridView的列
        /// </summary>
        /// <param name="theDataColumn"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private DataGridViewColumn CreateGridColumn(DataColumn theDataColumn)
        {
            DataGridViewColumn dColumn;
            switch (true)
            {
                case object _ when ReferenceEquals(theDataColumn.DataType, typeof(string)):
                    {
                        dColumn = new DataGridViewTextBoxColumn() { Width = 100 };
                        break;
                    }
                case object _ when ReferenceEquals(theDataColumn.DataType, typeof(int)):
                    {
                        dColumn = new DataGridViewTextBoxColumn() { Width = 50 };
                        if (theDataColumn.ColumnName.Length > 3)
                            dColumn.Width = 60;
                        if (theDataColumn.ColumnName.Length > 4)
                            dColumn.Width = 70;
                        dColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                        break;
                    }
                case object _ when ReferenceEquals(theDataColumn.DataType, typeof(double)):
                    {
                        dColumn = new DataGridViewTextBoxColumn() { Width = 65 };
                        dColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                        dColumn.DefaultCellStyle.Format = "0.##";
                        break;
                    }
                case object _ when ReferenceEquals(theDataColumn.DataType, typeof(decimal)):
                    {
                        dColumn = new DataGridViewTextBoxColumn() { Width = 65 };
                        dColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                        dColumn.DefaultCellStyle.Format = "0.00";
                        break;
                    }
                case object _ when ReferenceEquals(theDataColumn.DataType, typeof(DateTime)):
                    {
                        dColumn = new DataGridViewTextBoxColumn() { Width = 105 };
                        if (theDataColumn.ExtendedProperties.ContainsKey("Format"))
                        {
                            dColumn.DefaultCellStyle.Format = theDataColumn.ExtendedProperties["Format"]!.ToString();
                        }
                        else
                        {
                            dColumn.DefaultCellStyle.Format = "yyyy-MM-dd HH:mm";
                        }

                        break;
                    }
                case object _ when ReferenceEquals(theDataColumn.DataType, typeof(bool)):
                    {
                        dColumn = new DataGridViewCheckBoxColumn() { Width = 35 };
                        if (theDataColumn.ColumnName.Length > 1)
                            dColumn.Width = 40;
                        dColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        break;
                    }
                default:
                    {
                        dColumn = new DataGridViewTextBoxColumn() { Width = 100 };
                        break;
                    }
            }

            dColumn.DataPropertyName = theDataColumn.ColumnName;
            dColumn.HeaderText = theDataColumn.ColumnName;
            if (mBillSel.BillHideColumns.Contains(theDataColumn.ColumnName))
                dColumn.Visible = false;
            return dColumn;
        }

        private void RefreshMe(bool theFirstLoad = false)
        {
            var dTable = mBillSel.RefreshBill();
            if (dTable is null)
            {
                dgvList.DataSource = null;
                dgvWare.DataSource = null;
                return;
            }

            if (theFirstLoad)
            {
                // 创建列,设置格式,为各种类型设置默认宽度
                dgvList.Columns.Clear();
                for (int xx = 0; xx < dTable.Columns.Count; xx++)
                {
                    var dColumn = CreateGridColumn(dTable.Columns[xx]);
                    dgvList.Columns.Add(dColumn);
                }

                SetBillWidthsDefault();
                if (mBillSel.BillWidthsDefault != null) dgvList.LoadLayout(mBillSel.KeyMain, mBillSel.ModuleName);
            }

            dgvList.DataSource = dTable;
            if (dTable.Rows.Count == 0) dgvWare.DataSource = null;
        }

        private void BtnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void DgvList_SelectionChanged(object sender, EventArgs e)
        {
            var row = dgvList.SelectedRow;
            if (row == null)
            {
                dgvWare.DataSource = null;
                return;
            }

            var dTable = mBillSel.RefreshDetail(((DataRowView)row.DataBoundItem).Row);
            if (dTable is null)
            {
                dgvWare.DataSource = null;
                return;
            }

            if (mGridWareLoaded == false)
            {
                // 当第一次载入数据时,重新创建列
                dgvWare.Columns.Clear();
                for (int xx = 0; xx < dTable.Columns.Count; xx++)
                {
                    var dColumn = CreateGridColumn(dTable.Columns[xx]);
                    dgvWare.Columns.Add(dColumn);
                }

                SetDetailWidthsDefault();
                if (mBillSel.DetailWidthsDefault != null) dgvWare.LoadLayout(mBillSel.KeyMain, mBillSel.ModuleName);
                mGridWareLoaded = true;
            }

            dgvWare.DataSource = dTable;
        }

        private void BtnOK_Click(object sender, EventArgs e)
        {
            var row = dgvList.SelectedRow;
            if (row == null) return;

            if (mSelectedConfirm is not null)
            {
                var dRow = ((DataRowView)row.DataBoundItem).Row;

                if (mSelectedConfirm(dRow) == false) return;
            }

            mIsOK = true;
            Close();
        }

        private void FrmBillSel_Shown(object sender, EventArgs e)
        {
            if (mBillSel is null) return;
            if (mBillSel.Controls.Count == 0)
            {
                dgvList.Focus();
            }
        }
    }

    /// <summary>
    /// 单据选择窗体的适配类(基类),必须继承使用
    /// </summary>
    /// <remarks></remarks>
    /// <remarks>
    /// theModule:模块名称,用于为不同的模块加载不同的列宽度设置, theTitle:标题名称,显示在窗口标题栏上
    /// </remarks>
    /// <param name="theKeyMain"></param>
    /// <param name="theModule"></param>
    /// <param name="theTitle"></param>
    /// <remarks></remarks>
    public abstract class CBillSelBase(string theKeyMain, string theModule, string theTitle = "单据选择")
    {
        /// <summary>
        /// 刷新单据列表,如果时间的格式与默认格式不同,请为DataColumn.ExtendedProperties添加一个以Format为键的格式化文本
        /// </summary>
        /// <remarks></remarks>
        public abstract DataTable RefreshBill();

        /// <summary>
        /// 刷新明细列表,如果时间的格式与默认格式不同,请为DataColumn.ExtendedProperties添加一个以Format为键的格式化文本
        /// <para>theBillID 不为 null</para>
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public abstract DataTable RefreshDetail(DataRow theBillID);

        /// <summary>
        /// 参数控件集合,建议不要超过四个,显示顺序将按照创建顺序,添加参数控件的动作只应在New函数中完成,且不应该再次修改
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public CBillSelBaseArgsCollection Controls { get; private set; } = new CBillSelBaseArgsCollection();

        /// <summary>
        /// 显示在窗口标题栏上的文本
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        internal string Title { get; private set; } = theTitle;

        /// <summary>
        /// 为区别不同模块而设置的名称
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        internal string ModuleName { get; private set; } = theModule;

        /// <summary>
        /// 应用程序标识
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        internal string KeyMain { get; private set; } = theKeyMain;

        /// <summary>
        /// 单据列表各列默认宽度,不大于0表示未设置,只应在New中设置
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public int[]? BillWidthsDefault { get; set; } = null;

        /// <summary>
        /// 明细列表各列默认宽度,不大于0表示未设置,只应在New中设置
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public int[]? DetailWidthsDefault { get; set; } = null;
        /// <summary>
        /// 单据列表中需要隐藏的所有列的列名
        /// </summary>
        /// <returns></returns>
        public string[] BillHideColumns { get; set; } = [];
        /// <summary>
        /// 明细列表中需要隐藏的所有列的列名
        /// </summary>
        /// <returns></returns>
        public string[] DetailHideColumns { get; set; } = [];
    }

    public class CBillSelBaseArgsCollection
    {
        private readonly List<CBillSelBaseArgs> mList = [];

        public int Count => mList.Count;

        public CBillSelBaseArgs this[int Index] => mList[Index];

        public void Clear()
        {
            mList.Clear();
        }

        /// <summary>
        /// 创建并返回一个新的参数选项(日期范围选择控件)
        /// </summary>
        /// <param name="theStartDate"></param>
        /// <param name="theEndDate"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public CBillSelDateSelectArea AddDateSelectArea(DateTime theStartDate, DateTime theEndDate)
        {
            var dItem = new CBillSelDateSelectArea(theStartDate, theEndDate);
            mList.Add(dItem);
            return dItem;
        }

        /// <summary>
        /// 创建并返回一个新的参数选项(文本框控件),theCaption 为选项的说明,在控件的左边
        /// </summary>
        /// <param name="theCaption"></param>
        /// <param name="theDefaultText"></param>
        /// <remarks></remarks>
        public CBillSelTextBox AddTextBox(string theCaption, string theDefaultText = "")
        {
            var dItem = new CBillSelTextBox(theCaption, theDefaultText);
            mList.Add(dItem);
            return dItem;
        }

        /// <summary>
        /// 创建并返回一个新的参数选项(文本选择框控件), theCaption 为选项的说明,在控件的左边
        /// </summary>
        /// <param name="theCaption"></param>
        /// <param name="theDefaultValue"></param>
        /// <param name="theDefaultDisplayText"></param>
        /// <remarks></remarks>
        public CBillSelTextItem AddTextItem(string theCaption, object? theDefaultValue = null, string theDefaultDisplayText = "")
        {
            var dItem = new CBillSelTextItem(theCaption, theDefaultValue, theDefaultDisplayText);
            mList.Add(dItem);
            return dItem;
        }

        /// <summary>
        /// 创建并返回一个新的参数选项(说明项),theDescription为说明内容
        /// </summary>
        /// <param name="theDescription"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public CBillSelDescription AddDescription(string theDescription = "")
        {
            var dItem = new CBillSelDescription(theDescription);
            mList.Add(dItem);
            return dItem;
        }
    }

    public abstract class CBillSelBaseArgs
    {
        internal CBillSelBaseArgs(EmBillSelBaseArgs theArgs, string theCaption = "")
        {
            Args = theArgs;
            Caption = theCaption;
        }

        /// <summary>参数</summary>
        internal EmBillSelBaseArgs Args { get; private set; }
        public string Caption { get; private set; }
    }

    public class CBillSelDateSelectArea : CBillSelBaseArgs
    {
        private DateTime mStartDate;
        private DateTime mEndDate;

        internal CBillSelDateSelectArea(DateTime theStartDate, DateTime theEndDate) : base(EmBillSelBaseArgs.DateSelectArea)
        {
            mStartDate = theStartDate;
            mEndDate = theEndDate;
        }

        /// <summary>
        /// 返回起始时间.
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public DateTime StartDate => mStartDate;

        internal void SetDate(DateTime theStartDate, DateTime theEndDate)
        {
            mStartDate = theStartDate;
            mEndDate = theEndDate;
        }

        /// <summary>
        /// 返回结束时间. 用于控件的初始设置
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public DateTime EndDate => mEndDate;
    }

    public class CBillSelTextBox : CBillSelBaseArgs
    {
        private string mText = "";

        internal CBillSelTextBox(string theCaption, string theDefaultText = "") : base(EmBillSelBaseArgs.TextBox, theCaption) => mText = theDefaultText;

        /// <summary>
        /// 返回控件的文本
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public string Text => mText;

        internal void SetText(string theText) => mText = theText;
    }

    public class CBillSelTextItem(string theCaption, object? theDefaultValue = null, string theDefaultDisplayText = "") : CBillSelBaseArgs(EmBillSelBaseArgs.TextItem, theCaption)
    {
        /// <summary>
        /// 当请求选择一个项时发生,请使用e.InputText获取查询条件,并把结果传给e.Value
        /// </summary>
        /// <remarks></remarks>
        public event SelectItemEventHandler? SelectItem;
        public delegate void SelectItemEventHandler(object sender, CBillSelBaseTextItemArgs e);

        private object? mValue = theDefaultValue;
        private string mDisplayText = theDefaultDisplayText;

        /// <summary>
        /// 窗体方面专用,用于产生一个查询事件,并获取设置的内容
        /// </summary>
        /// <param name="theInputText"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        internal CBillSelBaseTextItemArgs SelectValue(string theInputText = "")
        {
            var dArgs = new CBillSelBaseTextItemArgs() { InputText = theInputText };
            SelectItem?.Invoke(this, dArgs);
            return dArgs;
        }

        /// <summary>返回控件设置的项</summary>
        public object? Value => mValue;

        /// <summary>返回控件显示的文本</summary>
        public string DisplayText => mDisplayText;

        internal void SetValue(object? theValue, string theDisplayText)
        {
            mValue = theValue;
            mDisplayText = theDisplayText;
        }
    }

    public class CBillSelBaseTextItemArgs : EventArgs
    {
        public object? Value { get; set; }
        public string DisplayText { get; set; } = "";
        public string? InputText { get; set; }
    }

    public class CBillSelDescription(string description) : CBillSelBaseArgs(EmBillSelBaseArgs.Descrioption, description)
    {
        private string mDescription = description;
        private Label? mLabel;

        internal void SetLabel(Label theLabel)
        {
            mLabel = theLabel;
        }

        /// <summary>
        /// 此方法只应在RefreshBill或者RefreshDetail中使用
        /// </summary>
        /// <param name="theDescription"></param>
        /// <remarks></remarks>
        public void SetDescription(string theDescription)
        {
            SetDescription(theDescription, Color.Green);
        }

        public void SetDescription(string theDescription, Color theForeColor)
        {
            mDescription = theDescription;
            if (mLabel is not null)
            {
                mLabel.Text = theDescription;
                mLabel.ForeColor = theForeColor;
            }
        }

        public string Description => mDescription;
    }

    public enum EmBillSelBaseArgs
    {
        DateSelectArea,
        TextBox,
        TextItem,
        Descrioption
    }
}